home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: How to tell if a file exists in C
- Date: Fri, 16 Feb 96 17:59:21 GMT
- Organization: none
- Message-ID: <824493561snz@genesis.demon.co.uk>
- References: <4eqkj6$ipo@charm.magnus.acs.ohio-state.edu> <4eqn9q$dr1@sparcserver.lrz-muenchen.de> <3121db3e.43150046@nntp.ix.netcom.com> <4ftpnk$i74@cafu.fl.net.au>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4ftpnk$i74@cafu.fl.net.au> als@fl.net.au "Andrew Snow" writes:
-
- >How about plain old:
- >
- > if(0==access("filename", F_OK))
- > {
- > do stuff with file();
- > }
- > else
- > {
- > error();
- > }
- >
- >This works O.K. under Linux and FreeBSD, and most DOS compilers.
-
- access() is a specialised function under Unix/POSIX to test permissions
- against the real user/group ID's. If you don't want to do that specifically
- you should never use access() (and why on other systems you should avoid it
- where portability is concerned). stat() is the way to go in that case.
-
- However neither of these are as portable as fopen() since that is defined by
- the C language.
-
- >If you want to see if the file is readable as well as exists,
-
- Can a file be readable yet not exist?
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-